function traceAdvancer3p0(traceNumber)
% traceAdvancer3p0     Callback function for traceBrowser uicontrol
%
% Editing:
% gs feb 2005 -- modified from traceAdvancer
% gs april 2005 -- modified from dualMapper as private for mapAnalysis3p0
% gs may 2006 - %GS20060524 - modified for ephus compatibility; flipud's added
% ----------------------------------------------------------------------

% get the data
handles = get(gcf, 'UserData');

% find the new trace number
if nargin == 0 % call was from slider/text
    style = get(gco, 'Style');
    switch style
        case 'edit'
            traceNumber = str2num(get(gco, 'String'));
        case 'slider'
            traceNumber = round(get(gco, 'Value'));
    end
elseif nargin == 1 % call was from pixTrace
end

% exit now if the trace number is off-scale
if traceNumber < 1 | traceNumber > size(handles.data.map.mapActive.bsArray, 2)
    return
end

% update the slider and text box
set(handles.data.fig.traceBrowser.htraceSlider, 'Value', traceNumber);
set(handles.data.fig.traceBrowser.htraceEdit, 'String', num2str(traceNumber));
handles.data.fig.traceBrowser.currentTrace = traceNumber;

% update the raw traces with the new values
set(handles.data.fig.traceBrowser.hcurrentTrace, 'YData', handles.data.map.mapActive.bsArray(:, traceNumber));
% if handles.data.analysis.numberOfMaps > 1
%     hold on;
%     for m = 2 : handles.data.analysis.numberOfMaps
%         strA = ['handles.data.map.map' num2str(m)];
%         strB = ['.bsArray(:, traceNumber)'];
%         strC = [strA strB];
%         
%         strD = ['handles.data.fig.traceBrowser.hcurrentTrace' num2str(m)];
% 
%         eval(['set(' strD ', ''YData'', ' strC ');']);
%             
% %         eval(['data.handles.hcurrentTrace' num2str(m) ...
% %                 ' = plot(xdata/handles.data.acq.sampleRate, ydataP1(:, ' num2str(m) '));']);
% %         set(gco, 'Color', handles.data.analysis.colorOrder(m));
%         % data.handles.hcurrentTraceP2 = plot(xdata/data.sampleRate, ydataP2, 'g-');
%     end
% end

% set(data.handles.hcurrentTraceP2, 'YData', data.P2.bsArrayP2(:, traceNumber));
axes(handles.data.fig.traceBrowser.hax1);
set(handles.data.fig.traceBrowser.hstimLine, 'YData', ...
    [min(handles.data.map.mapActive.bsArray(:, traceNumber)) max(handles.data.map.mapActive.bsArray(:, traceNumber))]);
axis tight;

% update the lines in the raw trace plot
set(handles.data.fig.traceBrowser.hstimLine, 'YData', get(handles.data.fig.traceBrowser.hax1, 'YLim'));

% update pixel-indicating marker in maps
[row col] = find(flipud(handles.data.map.mapActive.mapPattern) == handles.data.fig.traceBrowser.currentTrace); % GS20060524
y = (row - 1) * handles.data.map.mapActive.mapSpacing - handles.data.map.mapActive.magFacY;
x = (col - 1) * handles.data.map.mapActive.mapSpacing - handles.data.map.mapActive.magFacX;
set(handles.data.fig.traceBrowser.haxMap1_currentTrace, 'XData', x, 'YData', y);
% set(handles.data.fig.traceBrowser.haxMap2_currentTrace, 'XData', x, 'YData', y);
set(handles.data.fig.traceBrowser.haxSliceImg_currentTrace, 'XData', x, 'YData', y);

% % update the xcorr data
% set(data.handles.hxcorr1, 'YData', data.xcorr.XC(:, traceNumber)');
% 
% % lines in the xcorr plot
% set(data.handles.hzeroLine, 'YData', ...
%     [min(data.xcorr.XC(:, traceNumber)) max(data.xcorr.XC(:, traceNumber))]);
% set(data.handles.hmaxXCorr, 'YData', ...
%     [min(data.xcorr.XC(:, traceNumber)) max(data.xcorr.XC(:, traceNumber))], ...
%     'XData', [data.xcorr.maxXCorrLags(traceNumber) data.xcorr.maxXCorrLags(traceNumber)]);
% 
% axes(data.handles.hax2);
% axis tight;
% 
% % update the lines in the xcorr plot
% set(data.handles.hzeroLine, 'YData', get(data.handles.hax2, 'YLim'));
% set(data.handles.hmaxXCorr, 'YData', get(data.handles.hax2, 'YLim'));
